﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using myomscl.Interfaces;
using myomscl.Utils;
using omsData;
namespace myomscl.Presenters
{
    /// <summary>
    /// Base functionality all Presenters should support
    /// </summary>
    public abstract class Presenter
    {
        #region Declarations
        protected readonly IView _view;
        #endregion

        #region Constructor
        internal Presenter(IView view, ISessionProvider session)
        {
            _view = view;

            if (session != null)
            {
                SessionManager.Current = session;
            }
        }
        #endregion

        /// <summary>
        /// Converts an object from IView to the type of view the Presenter expects
        /// </summary>
        /// <typeparam name="T">Type of view to return (i.e. ILoginView)</typeparam>
        protected T GetView<T>() where T : class, IView
        {
            return _view as T;
        }
        /// <summary>
        /// Returns an object responsible for providing user session state
        /// </summary>
        protected ISessionProvider Session
        {
            get { return SessionManager.Current; }
        }

        //protected EstateDataSet.AlertChangesDataTable Changes
        //{
        //    get
        //    {
        //        if (Session[Constants.Changes] == null)
        //        {
        //            Session[Constants.Changes] = new EstateDataSet.AlertChangesDataTable();
        //        }
        //        return Session[Constants.Changes] as EstateDataSet.AlertChangesDataTable;
        //    }
        //    set
        //    {
        //        Session[Constants.Changes] = value;
        //    }
        //}

        //protected Filter Filters
        //{
        //    get
        //    {
        //        if (Session[Constants.Filters] == null)
        //        {
        //            Session[Constants.Filters] = new Filter();
        //        }
        //        return Session[Constants.Filters] as Filter;
        //    }
        //    set
        //    {
        //        Session[Constants.Filters] = value;
        //    }
        //}

        protected User CurrentUser
        {
            get
            {
                if (Session[Constants.CurrentUser] == null)
                {
                    return null;
                }
                return Session[Constants.CurrentUser] as User;
            }
            set
            {
                Session[Constants.CurrentUser] = value;
            }
        }

        protected List<Order> TempChanges
        {
            get
            {
                if (Session["TempChanges"] == null)
                {
                    Session["TempChanges"] = new List<Order>();
                }
                return Session["TempChanges"] as List<Order>;
            }
            set
            {
                Session["TempChanges"] = value;
            }
        }
    }

    public delegate void EmptyEventHandlerDelegate();
}
